package blackjack.android;

import blackjack.android.R.drawable;
import android.app.Activity;
import android.content.Intent;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.Spinner;
import android.widget.Toast;
import android.content.Context;

public class Main extends Activity implements OnClickListener
{
	Deck usedeck;
	Deck countdeck;
	Hand dealerhand = new Hand();
    Hand playerhand = new Hand();
    LinearLayout mLinearLayout;
    char name[];

	
	public void images()  
	{
		Resources res = getResources();
		Drawable clubs10 = res.getDrawable(R.drawable.clubs10);
		Resources res1 = getResources();
		Drawable clubs9 = res.getDrawable(R.drawable.clubs9);
		Resources res2 = getResources();
		Drawable clubs8 = res.getDrawable(R.drawable.clubs8);
		Resources res3 = getResources();
		Drawable clubs7 = res.getDrawable(R.drawable.clubs7);
		Resources res4 = getResources();
		Drawable clubs6 = res.getDrawable(R.drawable.clubs6);
		Resources res5 = getResources();
		Drawable clubs5 = res.getDrawable(R.drawable.clubs5);
		Resources res6 = getResources();
		Drawable clubs4 = res.getDrawable(R.drawable.clubs4);
		Resources res7 = getResources();
		Drawable clubs3 = res.getDrawable(R.drawable.clubs3);
		Resources res8 = getResources();
		Drawable clubs2 = res.getDrawable(R.drawable.clubs2);
		Resources res9 = getResources();
		Drawable clubsa = res.getDrawable(R.drawable.clubsa);
		Resources res10 = getResources();
		Drawable diamonds10 = res.getDrawable(R.drawable.diamonds10);
		Resources res11 = getResources();
		Drawable diamonds9 = res.getDrawable(R.drawable.diamonds9);
		Resources res12 = getResources();
		Drawable diamonds8 = res.getDrawable(R.drawable.diamonds8);
		Resources res13 = getResources();
		Drawable diamonds7 = res.getDrawable(R.drawable.diamonds7);
		Resources res14 = getResources();
		Drawable diamonds6 = res.getDrawable(R.drawable.diamonds6);
		Resources res15 = getResources();
		Drawable diamonds5 = res.getDrawable(R.drawable.diamonds5);
		Resources res16 = getResources();
		Drawable diamonds4 = res.getDrawable(R.drawable.diamonds4);
		Resources res17 = getResources();
		Drawable diamonds3 = res.getDrawable(R.drawable.diamonds3);
		Resources res18 = getResources();
		Drawable diamonds2 = res.getDrawable(R.drawable.diamonds2);
		Resources res19 = getResources();
		Drawable diamondsa = res.getDrawable(R.drawable.diamondsa);
		Resources res20 = getResources();
		Drawable hearts10 = res.getDrawable(R.drawable.hearts10);
		Resources res21 = getResources();
		Drawable hearts9 = res.getDrawable(R.drawable.hearts9);
		Resources res22 = getResources();
		Drawable hearts8 = res.getDrawable(R.drawable.hearts8);
		Resources res23 = getResources();
		Drawable hearts7 = res.getDrawable(R.drawable.hearts7);
		Resources res24 = getResources();
		Drawable hearts6 = res.getDrawable(R.drawable.hearts6);
		Resources res25 = getResources();
		Drawable hearts5 = res.getDrawable(R.drawable.hearts5);
		Resources res26 = getResources();
		Drawable hearts4 = res.getDrawable(R.drawable.hearts4);
		Resources res27 = getResources();
		Drawable hearts3 = res.getDrawable(R.drawable.hearts3);
		Resources res28 = getResources();
		Drawable hearts2 = res.getDrawable(R.drawable.hearts2);
		Resources res29 = getResources();
		Drawable heartsa = res.getDrawable(R.drawable.heartsa);
		Resources res30 = getResources();
		Drawable spades10 = res.getDrawable(R.drawable.spades10);
		Resources res31 = getResources();
		Drawable spades9 = res.getDrawable(R.drawable.spades9);
		Resources res32 = getResources();
		Drawable spades8 = res.getDrawable(R.drawable.spades8);
		Resources res33 = getResources();
		Drawable spades7 = res.getDrawable(R.drawable.spades7);
		Resources res34 = getResources();
		Drawable spades6 = res.getDrawable(R.drawable.spades6);
		Resources res35 = getResources();
		Drawable spades5 = res.getDrawable(R.drawable.spades5);
		Resources res36 = getResources();
		Drawable spades4 = res.getDrawable(R.drawable.spades4);
		Resources res37 = getResources();
		Drawable spades3 = res.getDrawable(R.drawable.spades3);
		Resources res38 = getResources();
		Drawable spades2 = res.getDrawable(R.drawable.spades2);
		Resources res39 = getResources();
		Drawable spadesa = res.getDrawable(R.drawable.spadesa);
		Resources res40 = getResources();
		Drawable spadesj = res.getDrawable(R.drawable.spadesj);
		Resources res41 = getResources();
		Drawable spadesk = res.getDrawable(R.drawable.spadesk);
		Resources res42 = getResources();
		Drawable spadesq = res.getDrawable(R.drawable.spadesq);
		Resources res43 = getResources();
		Drawable heartsk = res.getDrawable(R.drawable.heartsk);
		Resources res44 = getResources();
		Drawable heartsq = res.getDrawable(R.drawable.heartsq);
		Resources res45 = getResources();
		Drawable heartsj = res.getDrawable(R.drawable.heartsj);
		Resources res46 = getResources();
		Drawable diamondsk = res.getDrawable(R.drawable.diamondsk);
		Resources res47 = getResources();
		Drawable diamondsj = res.getDrawable(R.drawable.diamondsj);
		Resources res48 = getResources();
		Drawable diamondsq = res.getDrawable(R.drawable.diamondsq);
		Resources res49 = getResources();
		Drawable clubsk = res.getDrawable(R.drawable.clubsk);
		Resources res50 = getResources();
		Drawable clubsj = res.getDrawable(R.drawable.clubsq);
		Resources res51 = getResources();
		Drawable clubsq = res.getDrawable(R.drawable.clubsq);
		
	}
	
	public void instantiate()
	{
		usedeck = new Deck();
		countdeck = new Deck();
	}
	
	public void display()
	{
		
		for (int card = 0; card < (playerhand.hand.size()+1); card++)
		{
		Card count = playerhand.hand.get(card);
		int suit = count.getSuit();
		int value = count.getValue();

		
	    // Instantiate an ImageView and define its properties
	    ImageView i = new ImageView(this);
	    i.setImageResource(value);
	    
	   

	    // Add the ImageView to the layout and set the layout as the content view
	    mLinearLayout.addView(i);
	    setContentView(R.layout.main);

		}
		
	}
	
	public void entergame()
	{
		super.onStop();
		Intent entergame = new Intent(Main.this, Setup.class);
		Main.this.startActivity(entergame);
		
	}
	
	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState)
	{
	    super.onCreate(savedInstanceState);
	    setContentView(R.layout.main);
	    instantiate();

		Spinner spinner = (Spinner) findViewById(R.id.player);
	    ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.players_array, android.R.layout.simple_spinner_item);
	    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
	    spinner.setAdapter(adapter);
	    
		Button button = (Button) findViewById(R.id.shuffle);
		button.setOnClickListener(this);
		
	}
	
	
	public void deal()
    {

    for (int j = 0, y = 0; j < 2; j++, y++)
    {
    	dealerhand.hand.add(usedeck.m_deck.get(j));
    	usedeck.m_deck.remove(j);
    	playerhand.hand.add(usedeck.m_deck.get(y));
    	usedeck.m_deck.remove(y);
    }
    

    	
    	
    	Toast t = Toast.makeText(this, String.format("%d", dealerhand.hand.size()), Toast.LENGTH_SHORT);
		t.show();
    
    }
	public void hit()
	{
		playerhand.hand.add(usedeck.m_deck.get(0));
		usedeck.m_deck.remove(0);
	}
	
	public void onClick(View v)
	{
		entergame();
		usedeck.shuffle();
		deal();
		display();
	}
	public void checkscores(int suit, int value)
	{
	//sum the value
	//switch
	//case 1: if 21 then win
	//case 2:if >21 bust
	//case 3:if <21
	//case 4:if rank of card 1 = rank of card two, open new activity with new button for split
	
	}
	
	
}